﻿using System;
using System.Data.SQLite;
using System.Windows.Forms;

namespace FinanceManager
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void loginbtn_Click(object sender, EventArgs e)
        {
            SQLiteCommand comm;
            DBCommon.conn.Open();
            comm = DBCommon.conn.CreateCommand();
            comm.CommandText = "select pass from admin where name='" + tbname.Text.ToString() + "'";
            SQLiteDataReader reader = comm.ExecuteReader();
            if (reader.Read())
            {
                if (tbpass.Text.Equals(reader["pass"].ToString()))
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("用户名、密码错误！");
                }
            }
            else
            {
                MessageBox.Show("用户名、密码错误！");
            }
            reader.Close();
            DBCommon.conn.Close();
        }

        private void LoginForm_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter){
                loginbtn.PerformClick();
            }
        }
    }
}
